<?php
/*
	
*/
defined('BY_JYA') or exit('Access Denied');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	$cangid=$_RQ['cangid'];
	if(!$cangid){
		exi('请选择庄园！','error');
	}
	$this->session('cangid',$cangid);
	$cang=pdo_get('jy_nongfee_cang',array('id'=>$cangid,'uniacid'=>$_SESSION['uniacid']));
	$return['cang']=$cang;
	$member=model('core/member')->detail($_SESSION['uid'],array('credit1','credit2','credit3','credit4','credit6','mobile','avatar','nickname'));
	$mymember=pdo_get('jy_nongfee_member',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	$member=array_merge($member,$mymember);
	$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
	$return['member']=$member;
	$params=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'cangid'=>$cangid,'status <='=>1);
    $orderby='createtime desc';
	$total='';
	$return['list']=pdo_getall('jy_nongfee_canlog',$params,$fields,'',$orderby);
	$return['canlognum']=count($return['list']);
	$return['isbaonum']=pdo_count('jy_nongfee_canlog',array('baobei >'=>1,'status <='=>1,'uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'cangid'=>$cangid));
	$return['lastbaonum']=$return['canlognum']-$return['isbaonum'];
	foreach($return['list'] as &$v){
			$v['jian_getrate']=$cang['jian_getrate'];
			$yaopaixu=pdo_getcolumn('jy_nongfee_yao',array('id'=>$v['cangid'],'uniacid'=>$_SESSION['uniacid']),'paixu');
			$status=pdo_getcolumn('jy_nongfee_yao',array('id'=>$v['yaoid'],'uniacid'=>$_SESSION['uniacid']),'status');
			$v['createtime']=date('Y-m-d H:i:s',$v['createtime']);
			$v['statustitle']=$this->yao_status[$status];
			$v['title']='第'.$yaopaixu.''.$this->y_title;
	}
	$return['post']=array('baojifen'=>0,'payjifen'=>0,'canlogs'=>array());
	set_html('title','加倍包');
	exi($return);
}
// 完成下单
if($_RQ['op']=='post'){
	$cangid=$this->session('cangid');
	$post=get_postdata();
	$cangid=$this->session('cangid');
	if(!$post['baobei'] || $post['baobei']<=1){
		exi('请选择加倍包！倍数不能小于等于1','error');
	}
	if(!$post['payjifen']){
		exi('请需支付积分不能为0！','error');
	}
	$member=model('core/member')->detail($_SESSION['uid'],array('credit1','credit2','credit3','credit4','credit6','mobile','avatar','nickname'));
	$payjifen=$post['payjifen'];
	if($payjifen>$member['credit1']){
		exi('本次购买加倍包需消耗'.$payjifen.'积分，您的积分不足，不能参与！','error');
	}
	foreach($post['canlogs'] as $id=>$item){
		if($item){
			pdo_update('jy_nongfee_canlog',array('baobei'=>$post['baobei']),array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
			$canlog=pdo_get('jy_nongfee_canlog',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
			$canlog['canlogid']=$canlog['id'];
			$canlog['jifen']=$post['baojifen'];
			$this->model('model')->add_baolog($canlog);
		}
	}
	model('core/member')->member_credit($_SESSION['uid'],'credit1',$payjifen,false,'jy_nongfee','购买加倍包','duibao');
	exi('购买加倍包成功！','','jy_nongfee/detail//id='.$cangid);
}